class Solution1 {
    private int index ;
    public TreeNode buildTree(int[] preorder, int[] inorder) {
        
        TreeNode root = buildTreeNode(preorder , inorder  , 0 , inorder.length-1);
        return root ;

    }
    public TreeNode buildTreeNode(int[] preorder, int[] inorder  
      , int left , int right){
     if(index >= preorder.length || left > right ){
        return null ;
     }
      TreeNode node = null ;
      int i = left;
      for(; i <= right ; i++){
        if(preorder[index] == inorder[i]){
            node = new TreeNode(preorder[index]);
            break ;
        }
      }
      if(node == null){
        return null ;
      }
       index ++ ;
      node.left = buildTreeNode(preorder , inorder, left , i-1);
      node.right = buildTreeNode(preorder , inorder , i +1 , right);
        return node ;

     }                             


}